package com.example.spring.boot.rabbitmq.controller;

import com.alibaba.fastjson.JSON;
import com.example.spring.boot.rabbitmq.pojo.dto.DelayDTO;
import com.example.spring.boot.rabbitmq.pojo.vo.UserInfoVO;
import com.example.spring.boot.rabbitmq.service.DelaySenderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * DelayQueueConftroller
 * </p>
 *
 * @author weixin
 * @date 2023/3/28 14:55
 */
@RestController
@RequestMapping("/delay/")
public class DelayQueueController {


    @Resource
    private DelaySenderService service;

    @GetMapping("sendDelay")
    public void sendDelay(@RequestBody DelayDTO delayDTO) {

        UserInfoVO userInfoVO = new UserInfoVO();
        userInfoVO.setUserId("1638439522834845696");
        userInfoVO.setName("张三");
        userInfoVO.setAge(18);
        userInfoVO.setCreateTime(System.currentTimeMillis());

        String userInfoJson = JSON.toJSONString(userInfoVO);
        service.sendDelayMessage(userInfoJson, delayDTO.getDelayTime());
    }

}
